#!/usr/bin/env python3
"""
更新Excel数据源配置脚本
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from sqlalchemy.orm import sessionmaker
from core.database import engine
from models.data_source import ExcelConfig

def update_excel_config():
    """更新Excel配置"""
    Session = sessionmaker(bind=engine)
    session = Session()
    
    try:
        # 获取Excel配置
        excel_config = session.query(ExcelConfig).filter(ExcelConfig.data_source_id == 2).first()
        if excel_config:
            # CSV文件默认工作表名为Sheet1
            excel_config.sheet_name = None  # 对于CSV文件，不需要指定工作表名
            session.commit()
            print(f"已更新Excel配置，数据源ID: {excel_config.data_source_id}")
        else:
            print("未找到Excel配置")
        
    except Exception as e:
        session.rollback()
        print(f"更新Excel配置失败: {e}")
    finally:
        session.close()

if __name__ == "__main__":
    update_excel_config()